<template>
	<view class="flex flex-column justify-start align-center p-2" >
		
		<view class="flex justify-center align-center" style="width: 100%; height: 500rpx;" v-if=" exit" >
			暂无订单
		</view>
		<view class="" v-else>
			<view class="my-2 px-3 flex justify-between align-center" @click="goOrder(item._id)"
				style="box-shadow: 2px 2px 2px #b886fe; width: 600rpx; height: 200rpx; background-color: #fff; border-radius: 25rpx;"
				v-for="item in orderList">
				<view class="left flex align-center">
					<view class="avatar"
						style="width: 140rpx; height: 140rpx; border-radius: 100rpx; overflow: hidden; border: 2px solid #b987ff;">
						<image :src="item.submit_user[0].avater" style="width: 100%;" mode="widthFix">
						</image>
					</view>
					<view class="text ml-3" style="font-size: 50rpx; font-weight: bold; color: #7e5bad;">
						{{item.submit_user[0].nickname}}
					</view>
				</view>
				<view class="rate">
					<el-button @click.stop="goRate(item._id,item.submit_user[0]._id)" round size="medium"
						style="background-color: #b886fe; color: #fff;">立即评价</el-button>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database()
	export default {
		data() {
			return {
				orderList: [],
				userInfo: {},
				idList: [],
				exit:false
			};
		},
		async onLoad() {
			uni.showLoading({

			})
			await uni.getStorage({
				key: 'jiajiao_demo_account',
				success: res => {
					this.userInfo = res.data
				}
			})
			await db.collection('jiajiao_users').doc(this.userInfo._id).field('orderList').get().then(res => {
				if (res.result.data[0].orderList)
					this.idList = res.result.data[0].orderList
			})

			if (this.idList.length > 0) {
				for (let i = 0; i < this.idList.length; i++) {
					let orderTemp = db.collection("order").where({
						_id: this.idList[i]
					}).field('submit_user').getTemp()
					let userTemp = db.collection('jiajiao_users').field('_id,avater,nickname').getTemp()

					db.collection(orderTemp, userTemp).get().then(res => {
						this.orderList = res.result.data
						this.exit = false
					})
				}
			}
			else {
				this.exit = true
			}
			
			uni.hideLoading()

		},
		methods: {
			goOrder(id) {
				uni.navigateTo({
					url: `/pages/orderDetail/orderDetail?order_id=${id}&me=false`
				})
			},
			goRate(order_id, submit_id) {
				uni.navigateTo({
					url: `/pages/OrderRate/OrderRate?order_id=${order_id}&submit_id=${submit_id}`
				})
			}

		}

	}
</script>

<style lang="scss">
	page {
		background-color: #f1e5fe;
	}
</style>